using UnityEngine;
using System.Collections;
using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor;
#endif

public class PauseMenu : MonoBehaviour 
{
	public Canvas pauseMenu, saveMenu, loadMenu;
	
	void Start()
	{
		pauseMenu = GetComponent<Canvas>();
		pauseMenu.enabled = false;
		saveMenu.enabled = false;
		loadMenu.enabled = false;
	}
	
	void Update()
	{
		if (Input.GetKeyDown(KeyCode.Escape) && !saveMenu.enabled && !loadMenu.enabled)
		{
			Pause();
		}
	}

	public void Pause()
	{
		pauseMenu.enabled = !pauseMenu.enabled;
		Time.timeScale = Time.timeScale == 0 ? 1 : 0;
	}
	
	public void LoadGame()
	{
		Application.LoadLevel (1);
		Time.timeScale = Time.timeScale == 0 ? 1 : 0;
	}

	public void LoadMainMenu()
	{
		Application.LoadLevel (0);
		Time.timeScale = Time.timeScale == 0 ? 1 : 0;
	}
	
	public void KillGame()
	{
		#if UNITY_EDITOR 
		EditorApplication.isPlaying = false;
		#else 
		Application.Quit();
		#endif
	}
	
	public void CloseMenu()
	{
		pauseMenu.enabled = false;
		Time.timeScale = Time.timeScale == 0 ? 1 : 0;
	}

	public void SaveMenu()
	{
		pauseMenu.enabled = false;
		saveMenu.enabled = true;
	}

	public void CloseSaveMenu()
	{
		saveMenu.enabled = false;
		Time.timeScale = Time.timeScale == 0 ? 1 : 0;
	}

	public void BackSaveMenu()
	{
		saveMenu.enabled = false;
		pauseMenu.enabled = true;
	}

	public void LoadMenu()
	{
		pauseMenu.enabled = false;
		loadMenu.enabled = true;
	}

	public void CloseLoadMenu()
	{
		loadMenu.enabled = false;
		Time.timeScale = Time.timeScale == 0 ? 1 : 0;
	}

	public void BackLoadMenu()
	{
		loadMenu.enabled = false;
		pauseMenu.enabled = true;
	}
}